
Exp_time_post_start=xlsread('C:\Users\georg\Documents\AV_exp_time_post_mouse_on_ball.xlsx');

fract_time_running=[];


cnt=0;
for ind=1:length(AV_data)
    if length(AV_data(ind).shutter_open)==2
        PStmp=AV_data(ind).PS;
        PStmp(1:AV_data(ind).shutter_open(2)+100)=0;
        intervals_start=round([AV_data(ind).shutter_open(1)  find(diff(PStmp>0.2)==1)]/10);
        intervals_end=round([AV_data(ind).shutter_open(2)  find(diff(PStmp>0.2)==-1) length(AV_data(ind).PS)]/10);
    elseif length(AV_data(ind).shutter_open)>2
        intervals_start=round(AV_data(ind).shutter_open/10);
        intervals_end=round([AV_data(ind).shutter_open(2:end) length(AV_data(ind).PS)]/10);
    else
        intervals_start=round(AV_data(ind).shutter_open(1)/10);
        intervals_end=round(length(AV_data(ind).PS)/10);
    end
    for knd=1:length(intervals_start)
        cnt=cnt+1;
        fract_time_running(cnt,1)=sum(AV_data(ind).velP_ind(intervals_start(knd):intervals_end(knd)))/(intervals_end(knd)-intervals_start(knd));
        if fract_time_running(cnt,1)>1
            keyboard
        end
        fract_time_running(cnt,2)=Exp_time_post_start(Exp_time_post_start(:,1)==AV_data(ind).ExpID,2)+intervals_start(knd)/100/60;
        if AV_data(ind).ACode==1
            if knd==1
                fract_time_running(cnt,3)=1;
            else
                fract_time_running(cnt,3)=2;
            end
        elseif AV_data(ind).ACode==10
            fract_time_running(cnt,3)=3;
        end
    end
end
    

figure;
hold on
clrind='kgr'
for ind=1:2
    curr_ind=fract_time_running(:,3)==ind;
    plot(fract_time_running(curr_ind,2),fract_time_running(curr_ind,1),'o','color',clrind(ind),'linewidth',2)
end
ylabel('Fraction of time spent running')
xlabel('Time post session start [min]')


% for ind=1:size(fract_time_running,1)
%     if fract_time_running(ind,3)==1
%         if ind>1
%             plot(xpoints,ypoints,'k');
%         end
%         xpoints=fract_time_running(ind,2);
%         ypoints=fract_time_running(ind,1);
%         
%     elseif fract_time_running(ind,3)==2
%         xpoints=[xpoints fract_time_running(ind,2)];
%         ypoints=[ypoints fract_time_running(ind,1)];
%     end
% end
%         



pb_fr_run=fract_time_running(fract_time_running(:,3)==2,1:2);
















